//
//  UILabel-Extesion.swift
//  Whiteboard
//
//  Created by point on 2018/1/4.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit
extension UILabel {
    convenience init(name:String, color:UIColor, fontSize:CGFloat , isBoldFont:Bool = false){
        self.init()
        if isBoldFont == true {
            self.font = UIFont.boldSystemFont(ofSize: fontSize)
        }else{
            self.font = UIFont(name: "iconfont", size: fontSize)
        }
        
        self.textColor=color
        self.text=name
    }
    
    convenience init(_ dcColor:UIColor, _ dcFontSize:CGFloat , _ text:String = ""){
        self.init()
        self.font = UIFont.systemFont(ofSize: dcFontSize)
        self.textColor=dcColor
        self.text = text
    }
    
    /// 小红点
    ///
    /// - Parameters:
    ///   - num: 数量
    ///   - point: 位置
    convenience init(num:Int , point:CGPoint){
        self.init()
        
        self.text = String(num)
        self.layer.cornerRadius = 6
        self.clipsToBounds = true
        self.backgroundColor = UIColor.red
        self.textColor = UIColor.white
        self.font = UIFont.systemFont(ofSize: 12)
        self.textAlignment = .center
        if num <= 0 {
            self.isHidden = true
            return
        }
        
        if num < 10 {
            self.frame = CGRect(x: point.x, y: point.y, width: 12, height: 12)
        }
        
        if num <= 99 {
            self.frame = CGRect(x: point.x, y: point.y, width: 24, height: 12)
        }
        
        if num >= 100 {
            self.frame = CGRect(x: point.x, y: point.y, width: 30, height: 12)
            self.text = "99+"
        }
    }
    
    
}
